package org.micode.demo.db.domain.dto;

import org.micode.demo.db.cache.user.SysUserCache;
import org.micode.demo.db.domain.entity.SysUserDO;
import org.micode.common.utils.StringExtUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 用户信息(sys_user) 数据传输类
 *
 * author: wutianbin
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SysUserDTO extends SysUserDO {

    /**
     * 角色ID列表
     */
    private List<Long> roleIdList;

    private Integer loginType;

    private String confirmPassword;

    private String sessionId;

    private String token;

    private String uuid;

    private String imageCode;

    @Override
    public String toString() {
        return "SysUserDTO{roleIdList=" + StringExtUtils.listToString(roleIdList) +
                ", loginType=" + loginType +
                ", sessionId='" + sessionId + "'" +
                ", token='" + token + "'" +
                ", uuid='" + uuid + "'" +
                ", imageCode='" + imageCode + "'" +
                ", " + super.toString() + "}";
    }

    public SysUserCache toUserAuthCache() {
        SysUserCache cache = new SysUserCache();
        cache.setToken(this.token);
        cache.setUserId(this.getUserId());
        cache.setUserType(this.getUserType());
        cache.setLoginApp(this.getUpdProg());
        cache.setLoginIp(this.getUpdIp());
        cache.setLastLoginTime(System.currentTimeMillis());
        return cache;
    }

}
